<?php
namespace Shopiuu\Model;

use Shopiuu\Http\RequestCore;

class Shipping extends Model{
    
    public function __construct($accessToken, $endpoint)
    {
        parent::__construct($accessToken, $endpoint);
    }

    /**
     * Create Shipping
     * @param array $params array(
        "name"=> "UPS" //配送方式名称 必填
        "interface"=> "firstaddedweight" //运费公式
        "status"=> "1" //状态， 1 开启 0 关闭
        "shipping_param"=> array(
            "first_weight"=> "0.5"
            "added_weight"=> "0.5"
            "first_price"=> "30"
            "added_price"=> "6"
            "freeshipping_price"=> "0"
            "freeshipping_num"=> "1"
            "limit_weight"=> "0"
        )
        "display_param"=> array(
            "amount_max"=> ""
            "amount_min"=> ""
            "country_whitelist"=> ""
            "country_blacklist"=> ""
        )
        "image"=> "//image.example.com/Upload/1/shipping/2021-05-31/55d8d850af608994.jpg" // 配送方式图片
        "time_descript"=> "" //时效说明
        "details"=> "" //配送方式说明
        "sort"=> "0" //排序
        "collect_image"=> "1" //是否采集图片
        "area_id"=> "0" //配送区域id
        "shipping_company_id"=> "0" //配送公司id
       )
     * @return ResponseCore
     */
    public function add($params)
    {
        $request = $this->getRequest('/openApi/shipping/add');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

    /**
     * Modify Shipping
     * @param array $params array(
        "name"=> "UPS" //配送方式名称 必填
        "interface"=> "firstaddedweight" //运费公式
        "status"=> "1" //状态， 1 开启 0 关闭
        "shipping_param"=> array(
            "first_weight"=> "0.5"
            "added_weight"=> "0.5"
            "first_price"=> "30"
            "added_price"=> "6"
            "freeshipping_price"=> "0"
            "freeshipping_num"=> "1"
            "limit_weight"=> "0"
        )
        "display_param"=> array(
            "amount_max"=> ""
            "amount_min"=> ""
            "country_whitelist"=> ""
            "country_blacklist"=> ""
        )
        "image"=> "//image.example.com/Upload/1/shipping/2021-05-31/55d8d850af608994.jpg" // 配送方式图片
        "time_descript"=> "" //时效说明
        "details"=> "" //配送方式说明
        "sort"=> "0" //排序
        "collect_image"=> "1" //是否采集图片
        "area_id"=> "0" //配送区域id
        "shipping_company_id"=> "0" //配送公司id
       )
     * @return ResponseCore
     */
    public function update($params)
    {
        $request = $this->getRequest('/openApi/shipping/update');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

    /**
     * Get Shipping
     * @param array $params array(
        "pagenum"=> 1 //页码
        "pagesize"=> 20 //每页数量
        "search"=> "keywords" //搜索标题
        "shipping_company_id"=> "1" //搜索配送公司id
        "orderfeild"=> "id" //排序字段
        "ordersort"=> "desc" //排序方式
     )
     * @return ResponseCore
     */
    public function getList($params)
    {
        $request = $this->getRequest('/openApi/shipping/lists');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

    /**
     * Get All Shippings
     * @param array $params array(
        "search"=> "keywords" //搜索标题
        "shipping_company_id"=> "1" //搜索配送公司id
        "orderfeild"=> "id" //排序字段
        "ordersort"=> "asc" //排序方式
     )
     * @return ResponseCore
     */
    public function getAllShippings($params)
    {
        $request = $this->getRequest('/openApi/shipping/getAllShippings');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }
    
    /**
     * Delete Shipping
     * @param array $params array("id"=>"25")
     * @return ResponseCore
     */
    public function delete($params)
    {
        $request = $this->getRequest('/openApi/shipping/delete');
        $result = $request->set_body(json_encode($params))->set_method('POST')->send_request(true);
        return $result;
    }

}